/**
 * 
 */
package sk.stuba.fiit.foo07.genex.beans;

import java.sql.SQLException;
import java.sql.Timestamp;

import sk.stuba.fiit.foo07.genex.common.ConnectionHelper;
import sk.stuba.fiit.foo07.genex.dao.CategoryDaoDerby;

/**
 * @author Martin
 * 
 */
public class Category {

    private String name;
    private String description;
    private Timestamp created;
    private Timestamp lastUpdate;
    private Integer categoryID;
    private Integer parentCategoryId;
    private Integer userTD;

    public Category() {

    }

    public Category(String name, String description, Timestamp created,
            Timestamp lastUpdate, Integer categoryID, Integer parentCategoryId,
            Integer userTD) {
        super();
        this.name = name;
        this.description = description;
        this.created = created;
        this.lastUpdate = lastUpdate;
        this.categoryID = categoryID;
        this.parentCategoryId = parentCategoryId;
        this.userTD = userTD;
    }

    /**
     * @return the parentCategoryId
     */
    public Integer getParentCategoryId() {
        return parentCategoryId;
    }

    /**
     * @param parentCategoryId
     *            the parentCategoryId to set
     */
    public void setParentCategoryId(Integer parentCategoryId) {
        this.parentCategoryId = parentCategoryId;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name
     *            the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @param description
     *            the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * @return the created
     */
    public Timestamp getCreated() {
        return created;
    }

    /**
     * @param created
     *            the created to set
     */
    public void setCreated(Timestamp created) {
        this.created = created;
    }

    /**
     * @return the lastUpdate
     */
    public Timestamp getLastUpdate() {
        return lastUpdate;
    }

    /**
     * @param lastUpdate
     *            the lastUpdate to set
     */
    public void setLastUpdate(Timestamp lastUpdate) {
        this.lastUpdate = lastUpdate;
    }

    /**
     * @return the categoryID
     */
    public Integer getCategoryID() {
        return categoryID;
    }

    /**
     * @param categoryID
     *            the categoryID to set
     */
    public void setCategoryID(Integer categoryID) {
        this.categoryID = categoryID;
    }

    /**
     * @return the userTD
     */
    public Integer getUserTD() {
        return userTD;
    }

    /**
     * @param userTD
     *            the userTD to set
     */
    public void setUserTD(Integer userTD) {
        this.userTD = userTD;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {

        CategoryDaoDerby cdd = new CategoryDaoDerby(ConnectionHelper
                .getConnection());
        StringBuilder count = new StringBuilder();
        count.append("(");
        try {
            count.append(cdd.questionCount(categoryID));
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        count.append(")");
        return this.name.concat(count.toString());
    }

}
